package com.youmu.sichuansfc.util;

import org.apache.log4j.Logger;

import java.awt.*;
import java.util.Random;

/**
 *  自定义随机生成类
 */
public class YZRandom {
    private Logger logger = org.apache.log4j.Logger.getLogger(YZRandom.class);
    /**
     * 邀请码Code
     */

    /**
     *  len个随机可重复大写字母
     * @param len
     * @return
     * @throws Exception
     */
    public String getInviteCode(int len) throws Exception {
        char[] chars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
        Random random = new Random();

        // 生成一个 len长度的 随机字符串
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < len; i++) {
            buff.append(chars[random.nextInt(chars.length)]);
        }

        logger.debug(buff);
        return buff.toString();
    }

    /**
     *  length 个随机大小写字母加数字字符串
     * @param length
     * @return
     */
    public static String createNoncestr(int length) {
        String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        String res = "";
        for (int i = 0; i < length; i++) {
            Random rd = new Random();
            res += chars.charAt(rd.nextInt(chars.length() - 1));
        }
        return res;
    }

    /**
     * 获取随机颜色
     * @return
     */
    public static Color getRandomColor() {
        Random random = new Random();
        return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255));
    }
}
